<template>
	<!--招采管理-物资招采列表-应标结果弹窗-表单-->
	<a-spin :spinning="confirmLoading">
		<j-form-container :disabled="formDisabled">
			<a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
				<a-row>
					<a-col :span="24" style="margin-top: 20px">
						<div class="table-page-search-wrapper">
							<a-form layout="inline" @keyup.enter.native="searchQuery">
								<a-row :gutter="24">
									<a-col :md="6" :sm="12">
										<a-form-item label="供应商名称">
											<j-input placeholder="输入供应商名称模糊查询" v-model="queryParam.name"></j-input>
										</a-form-item>
									</a-col>
									<a-col :md="6" :sm="8">
										<span style="float: left; overflow: hidden"
											class="table-page-search-submitButtons">
											<a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
											<a-button type="primary" @click="searchReset" icon="reload"
												style="margin-left: 8px">重置</a-button>
										</span>
									</a-col>
								</a-row>
							</a-form>
						</div>
						<span style="font-size:16px">请选择供应商:</span>
						<a-table ref="table" size="middle" :scroll="{ x: true }" bordered rowKey="id" :columns="columns"
							:dataSource="dataSource" :loading="loading" :row-key="(record) => record.id"
							:pagination="ipagination" :row-selection="{
                selectedRowKeys: selectedRowKeys,
                onChange: onSelectChange,
                onSelect: onSelect,
                onSelectAll: onSelectAll,
                getCheckboxProps: getCheckboxProps
              }" class="j-table-force-nowrap" @change="handleTableChange" v-model="model.supplier">
							<span slot="action" slot-scope="text, record">
								<a v-if="record.status == '1'" disabled>已应标</a>
								<a-divider v-if="record.status == '1'" type="vertical" />
								<a @click="handleqing(record)">详情</a>
								<a-divider type="vertical" />
								<a @click="handlepingjia(record)">评价</a>
							</span>
						</a-table>
					</a-col>
				</a-row>
			</a-form-model>
		</j-form-container>
		<wt-public-bidding-modal ref="modalForm" @ok="modalFormOk"></wt-public-bidding-modal>
		<Huiqian v-model="isShow" @handleOk="ok1" :supplierData="supplierData" :supplierDataList="supplierDataList"
			:publicBiddingId="publicBiddingId" :biddingSuppliersIds="biddingSuppliersIds" />
		<comment-modal ref="modalForm2" :pageType="pageType"></comment-modal>
	</a-spin>

</template>

<script>
	import {
		httpAction,
		getAction
	} from '@/api/manage'
	import {
		validateDuplicateValue
	} from '@/utils/util'
	import JDate from '@/components/jeecg/JDate'
	import {
		mixinDevice
	} from '@/utils/mixin'
	import {
		JeecgListMixin
	} from '@/mixins/JeecgListMixin'

	import WtPublicBiddingModal from "./WtRecruitResultxiangModal"
	import CommentModal from "./../components/CommentModal"
	import Bus from './bus'
	import Huiqian from './huiqian'
	export default {
		name: 'WtPublicBiddingForm',
		mixins: [JeecgListMixin, mixinDevice],
		components: {
			Huiqian,
			JDate,
			WtPublicBiddingModal,
			CommentModal
		},
		props: {
			//表单禁用
			disabled: {
				type: Boolean,
				default: false,
				required: false
			},
			id: {
				type: String
			},
			pageType: {
				type: String,
				default: '',
			}
		},
		data() {
			return {
				isShow: false,
				id: '',
				biddingSuppliers: '',
				dictOptions: {},
				superFieldList: [],
				queryParam: {
					type: '0',
					publicBiddingId: this.id
				},
				selectedRowKeys: [],
				selectedRows: [],
				columns: [{
						title: '序号',
						dataIndex: '',
						key: 'rowIndex',
						width: 60,
						align: 'center',
						customRender: function(t, r, index) {
							return parseInt(index) + 1
						}
					},
					{
						title: '供应商名称',
						align: 'center',
						dataIndex: 'supplierName'
					},
					{
						title: '状态',
						align: 'center',
						dataIndex: 'status_dictText',
					},
					{
						title: '操作',
						dataIndex: 'action',
						align: "center",
						fixed: "right",
						width: 155,

						scopedSlots: {
							customRender: 'action'
						}
					}
				],

				model: {
					supplier: ''
				},
				labelCol: {
					xs: {
						span: 24
					},
					sm: {
						span: 5
					}
				},
				wrapperCol: {
					xs: {
						span: 24
					},
					sm: {
						span: 16
					}
				},
				confirmLoading: false,
				validatorRules: {},
				supplierData: {},
				supplierDataList: [],
				publicBiddingId: '',
				biddingSuppliersIds: '',
				// supplierList:[],
				url: {
					list: '/bidding/wtBiddingSupplier/list',
					add: '/bidding/wtMaterialsSupplierPrice/add',
					edit: '/bidding/wtMaterialsSupplierPrice/add',
					queryById: '/bidding/wtPublicBidding/queryById'
				},
				ipagination: {},

			}
		},
		computed: {
			formDisabled() {
				return this.disabled
			}
		},

		beforeMount() {

		},
		created() {
			//备份model原始值
			this.modelDefault = JSON.parse(JSON.stringify(this.model))

		},
		methods: {
			handlepingjia(record) {
				this.$refs.modalForm2.title = '评价';
				this.$refs.modalForm2.disableSubmit = false;
				this.$refs.modalForm2.edit(record);
			},
			getCheckboxProps(record) {
				return {
					props: {
						disabled: record.status != 1, // Column configuration not to be checked
						name: record.status,
					},
				}
			},
			ok1() {
				this.$emit('ok2')
			},
			initDictConfig() {},
			getSuperFieldList() {
				let fieldList = []
				fieldList.push({
					type: 'string',
					value: 'name',
					text: '名称',
					dictCode: ''
				})
				fieldList.push({
					type: 'int',
					value: 'type',
					text: '0经营产品1施工',
					dictCode: ''
				})
				fieldList.push({
					type: 'string',
					value: 'relation',
					text: '联系人',
					dictCode: ''
				})
				fieldList.push({
					type: 'string',
					value: 'phone',
					text: '电话',
					dictCode: ''
				})
				fieldList.push({
					type: 'string',
					value: 'address',
					text: '地址',
					dictCode: ''
				})
				fieldList.push({
					type: 'string',
					value: 'score',
					text: '评分',
					dictCode: ''
				})
				this.superFieldList = fieldList
			},

			add() {
				this.edit(this.modelDefault)
			},
			edit(record, type) {
				this.model = Object.assign({}, record)
				this.visible = true;
			},
			// 勾选触发的函数
			onSelectChange(selectedRowKeys) {
				// console.log('勾选：', selectedRowKeys)
				this.selectedRowKeys = selectedRowKeys
			},
			/**
			 * 表格单选事件
			 * @param record 行数据
			 * @param selected 是否选中
			 */
			onSelect(record, selected) {
				// 若选中，直接push
				if (selected) {
					this.selectedRows.push(record)
				} else {
					// 若取消选中，则查找到这条数据删除
					let index = this.selectedRows.findIndex((item) => item.id == record.id)
					if (index >= 0) {
						this.selectedRows.splice(index, 1)
					}
				}
			},
			/**
			 * 表格多选事件
			 * @param selected     是否选中
			 * @param selectedRows 忘记了，当时没用到
			 * @param changeRows   变化行数据
			 */
			onSelectAll(selected, selectedRows, changeRows) {
				// 若选中，直接push
				if (selected) {
					// 单选中部分几条数据，此时点击全选，将 changeRows 剩下的几条为选中数据选中
					this.selectedRows = this.selectedRows.concat(changeRows)
				} else {
					// 若取消选中，则为空
					this.selectedRows = []
				}
			},
			updateBidding(id) {
				// console.log('选中的id：', id)
				if (this.selectedRows.length <= 0) {
					return this.$message.warning('请先选中一条记录！')
				}

				const biddingSuppliersIds = this.selectedRows.map(item => item.id).join(',')
				this.loading = true
				this.publicBiddingId = id
				this.biddingSuppliersIds = biddingSuppliersIds
				getAction('/bidding/wtPublicBidding/getPreviewCountersignData', {
						publicBiddingId: id,
						biddingSuppliers: biddingSuppliersIds,
						// biddingSupplierStatus: '2',
						// status: '3',
					}, 'GET')
					.then(res => {
						if (res.success) {
							this.$message.success(res.message)
							var list = res.result.list ? res.result.list : []
							this.isShow = true
							var Data = res.result
							this.supplierData = Data
							this.supplierDataList = list
						} else {
							this.$message.warning(res.message)
						}
					})
					.finally(() => {
						this.confirmLoading = false
						this.loading = false
					})

			},
			submitForm() {
				const that = this
				// 触发表单验证
				this.$refs.form.validate(valid => {
					if (valid) {
						that.confirmLoading = true
						let httpurl = ''
						let method = ''
						if (!this.model.id) {
							httpurl += this.url.add
							method = 'post'
						} else {
							httpurl += this.url.edit
							method = 'post'
						}
						that.model.supplier = that.selectedRowKeys.join(',')
						httpAction(httpurl, that.model, method)
							.then(res => {
								if (res.success) {
									that.$message.success(res.message)
									that.$emit('ok')
								} else {
									that.$message.warning(res.message)
								}
							})
							.finally(() => {
								that.confirmLoading = false
							})
					}
				})
			}
		}
	}
</script>